from seleniumbase import BaseCase


class FrameTests(BaseCase):
    def test_iframe_basics(self):
        self.open("https://seleniumbase.io/w3schools/iframes.html")
        self.switch_to_frame("iframeResult")  # 输入 iframe
        self.assert_text("HTML Iframes", "h2")
        self.switch_to_frame('[title*="Iframe"]')  # 在 iframe 内输入 iframe
        self.assert_text("This page is displayed in an iframe", "h1")
        self.switch_to_default_content()  # 退出所有 iFrame
        self.click("button#runbtn")
        self.switch_to_frame("iframeResult")  # 返回第一个 iframe 内部
        self.highlight('iframe[title="Iframe Example"]')

    def test_set_content_to_frame(self):
        self.open("https://seleniumbase.io/w3schools/iframes.html")
        self.set_content_to_frame("iframeResult")
        self.highlight('iframe[title="Iframe Example"]')
        self.set_content_to_frame("iframe")
        self.assert_element_not_visible('iframe')
        self.highlight("body")
        self.set_content_to_default(nested=False)
        self.highlight('iframe[title="Iframe Example"]')
        self.set_content_to_default()
        self.click("button#runbtn")
        self.highlight("#iframeResult")
